/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package lab3;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author joser93
 */
public class Lab3 extends JFrame implements ActionListener{

    JTable tabla;
    
    String[] acciones={"Seleccionar TableSpace", "Migrar", "Eliminar", "Desfragmentar", "Limpiar"};
    String[] menu={"Creditos", "Salir"};
    
    public Lab3() throws HeadlessException {
        setTitle("Manejador Indices");
        configInicial();
        configComp();
        configMenu();
    }
    
    private void configComp(){
        Object[] col={"Nombre del Indice", "Tablespace", "Dueño", "Fragmentación", "Seleccionar"};
        DefaultTableModel model=new DefaultTableModel(null, col);
        tabla=new JTable(model){
            @Override
            public Class<?> getColumnClass(int column) {
                if(column<=2)
                    return String.class;
                else if(column==3)
                    return Boolean.class;
                return null;
            }
        };
        tabla.setPreferredScrollableViewportSize(tabla.getPreferredSize());
        JScrollPane scroll=new JScrollPane(tabla, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(scroll);
        
        JPanel botones=new JPanel(new FlowLayout());
        JButton b;
        for(String s:acciones){
            b=new JButton(s);
            b.addActionListener(this);
            botones.add(b);
        }
        botones.setBorder(BorderFactory.createTitledBorder("Opciones"));
        add(botones, BorderLayout.SOUTH);
    }
    
    private void configInicial(){
        setPreferredSize(new Dimension(650, 400));
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void mostrar(){
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }
    
    private void configMenu(){
        JMenuBar barra=new JMenuBar();
        this.setJMenuBar(barra);
        JMenu m1=new JMenu("General");
        barra.add(m1);
        JMenuItem i;
        for(String s:menu){
            i=new JMenuItem(s);
            i.addActionListener(this);
            m1.add(i);
        }
        m1=new JMenu("Opciones");
        barra.add(m1);
        for(String s:acciones){
            i=new JMenuItem(s);
            i.addActionListener(this);
            m1.add(i);
        }
    }
    
    public static void main(String[] args) {
        new Lab3().mostrar();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch(e.getActionCommand()){
            
            default:
                throw new UnsupportedOperationException("Not supported yet."+e.getActionCommand()); //To change body of generated methods, choose Tools | Templates.
        }
    }
    
}
